package commands;

import java.util.*;

import messages.*;
import user.User;
import core.*;
import event.*;


/**
 * The ListPlugins command.
 * 
 * This command will handle ListPlugins messages.
 */
public class ListPluginsCommand extends Command {

	
	public ListPluginsCommand(Message message, User user) {
		super(message, user);
	}
	
	
	@Override
	public void execute() {
		PluginManager pluginManager = controller.getPluginManager();
		
		Collection<Plugin> plugins = pluginManager.list();
		Collection<PluginInfo> pluginsInfo = new ArrayList<PluginInfo>();
		
		for (Plugin plugin : plugins) {
			pluginsInfo.add(new PluginInfo(plugin));
		}
		
		controller.fireListPluginsReplyEvent(new ListPluginsReplyEventArgs(
				this.user.getLogin(),
				new ListPluginsReplyMessage(pluginsInfo)));
	}
}
